Add friendly FES error for dimension mismatch on shared variable assi…#8823
Open
harshiltewari2004 wants to merge 1 commit into
Open
Add friendly FES error for dimension mismatch on shared variable assi…#8823harshiltewari2004 wants to merge 1 commit into
harshiltewari2004 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #8812
Changes
Adds a friendly error for the case where a value of the wrong dimension is assigned to a p5.strands shared variable. Previously, code like:
js let worldPosX = sharedVec3(); worldPosX = inputs.position.x; // scalar assigned to vec3 would emit invalid shader source (
vec3 = float) and bubble up as a cryptic GPU shader-compiler message such asERROR: 0:98: 'assign' : cannot convert from 'highp float' to 'highp 3-component vector of float', with no way for the user to map it back to the JS variable that caused it.After this PR, the same code throws at IR-construction time with:
[p5.strands dimension mismatch]: Cannot assign a value of dimension 1 to `worldPosX`, which expects dimension 3. This follows the four-call-site approach discussed in the plan comment on #8812 (factor out a shared helper, throw early via the existing
userErrorconvention).Implementation
A new
dimensionMismatchError(declaredDim, actualDim, varName)helper insrc/strands/strands_FES.jsis wired into the four sites that produce assignment IR nodes for strands-tracked variables:bridge()insrc/strands/strands_node.js— primary path forsharedX = valueafter the transpiler rewrites the assignment to.bridge(...).bridgeSwizzle()insrc/strands/strands_node.js— for swizzle writes likesharedX.xyz = value. Declared dimension comes fromswizzlePattern.length.swizzleTrap.setinsrc/strands/ir_builders.js— the existing partial dimension check was refactored to use the shared helper, preserving the broadcast (dim === 1) and exact-match cases.Object.definePropertysetter insrc/strands/strands_api.js— for hook-struct field writes likeworldInputs.position = newVec. Declared dimension comes frompropertyType.dataType.dimension.Broadcasting from a scalar (
dim === 1) is preserved as before, consistent with non-shared assignment behavior.Tests
Three tests added in both
test/unit/webgl/p5.Shader.jsandtest/unit/webgpu/p5.Shader.jsunder thep5.strandssuite:reports a friendly error when assigning a scalar to a sharedVec3 (bridge)reports a friendly error on dimension mismatch via swizzle write (bridgeSwizzle)does not error when shared variable assignment dimensions matchTest infrastructure note
Two small adjustments in
test/unit/webgl/p5.Shader.jsweren't part of the fix itself but were needed for the tests to run cleanly:vi.mockfactory forstrands_FESwas extended to includedimensionMismatchError. The existing mock only stubbeduserErrorandinternalError, so the new import broke module loading.afterEachmock-clearing hook in thep5.strands error messagessuite was changed tobeforeEach. The original only cleaned up after each test, so the suite's first test inheritedmockUserError.mock.calls[0]from any prior test in the file that had fired auserError. This was a latent fragility that the new tests happened to expose —beforeEachdefends against it generally.Screenshots of the change
N/A — error-message change only. Before/after messages included above.
PR Checklist
npm run lintpasses